package com.design3.graduatethesissys.configure; 
/** 
* @author 作者 罗穆健: 
* @version 创建时间：2020年1月5日 下午11:00:57 
* 类说明 
*/

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Service;

import com.design3.graduatethesissys.common.utils.GsonUtil;
import com.design3.graduatethesissys.domain.UrlResponse;

@Service
public class UrlAccessDeniedHandler implements AccessDeniedHandler {
	@Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {

        UrlResponse response = new UrlResponse();
        response.setSuccess(false);
        response.setCode("403");
        response.setMessage("Need Authorities!");
        response.setData(null);

        httpServletResponse.setStatus(403);
        httpServletResponse.getWriter().write(GsonUtil.GSON.toJson(response));
    }
}
 